+2008-03-29 Sven Neumann <sven@gimp.org>
+
+ * babl/babl-component.c
+ * babl/babl-conversion.c
+ * babl/babl-db.c
+ * babl/babl-extension.c
+ * babl/babl-fish-path.c
+ * babl/babl-fish-reference.c
+ * babl/babl-fish-simple.c
+ * babl/babl-format.c
+ * babl/babl-model.c
+ * babl/babl-type.c: applied patch from Jan Heller that changes the
+ code to test for a pre-existent instance of a babl class in the
+ database before creating a new one.
+
2008-03-24 Tor Lillqvist <tml@novell.com>
* babl/babl-type.c: Make the "test" array static.
va_end (varg);
+ babl = babl_db_exist (db, id, first_arg);
+ if (babl)
+ {
+ /* There is an instance already registered by the required id/name,
+ * returning the preexistent one instead.
+ */
+ return babl;
+ }
+
babl = component_new (first_arg, id, luma, chroma, alpha);
- {
- Babl *ret = babl_db_insert (db, babl);
- if (ret != babl)
- babl_free (babl);
- return ret;
- }
+ /* Since there is not an already registered instance by the required
+ * id/name, inserting newly created class into database.
+ */
+ babl_db_insert (db, babl);
+ return babl;
}
BABL_CLASS_TEMPLATE (component)
}
else if (planar)
{
- babl_fatal ("planar conversions not supported for %ssupported",
+ babl_fatal ("planar conversions not supported for %s",
babl_class_name (source->class_type));
}
break;
{
type = BABL_CONVERSION_PLANAR;
}
- babl = conversion_new (create_name (source, destination, type),
- id, source, destination, linear, plane, planar);
-
- {
- Babl *ret = babl_db_insert (db, babl);
- if (ret != babl)
- babl_free (babl);
- else
- babl_add_ptr_to_list ((void ***) ((Babl *) &(source->type.from)), babl);
-
- return ret;
- }
+
+ char * name = create_name (source, destination, type);
+
+ babl = babl_db_exist (db, id, name);
+ if (babl)
+ {
+ /* There is an instance already registered by the required id/name,
+ * returning the preexistent one instead.
+ */
+ return babl;
+ }
+
+ babl = conversion_new (name, id, source, destination, linear, plane, planar);
+
+ /* Since there is not an already registered instance by the required
+ * id/name, inserting newly created class into database.
+ */
+ babl_db_insert (db, babl);
+ babl_add_ptr_to_list ((void ***) ((Babl *) &(source->type.from)), babl);
+ return babl;
}
static long
babl_db_insert (BablDb *db,
Babl *item)
{
-
- Babl *found = babl_db_exist (db, item->instance.id, item->instance.name);
-
- if (found)
- return found;
-
if (item->instance.id)
babl_hash_table_insert (db->id_hash, item);
babl_hash_table_insert (db->name_hash, item);
init = dlsym (dl_handle, "init");
if (!init)
{
- babl_log ("\n\tint babl_extension_init() function not found in extenstion '%s'", path);
+ babl_log ("\n\tint babl_extension_init() function not found in extension '%s'", path);
dlclose (dl_handle);
return load_failed (babl);
}
return load_failed (babl);
}
- if (babl_db_insert (db, babl) == babl)
+ babl_db_insert (db, babl);
+ if (babl == babl_db_exist_by_name (db, path))
{
babl_set_extender (NULL);
return babl;
char *name = create_name (source, destination, 1);
BablConversion *temp_chain[BABL_HARD_MAX_PATH_LENGTH];
+ babl = babl_db_exist_by_name (babl_fish_db (), name);
+ if (babl)
+ {
+ /* There is an instance already registered by the required name,
+ * returning the preexistent one instead.
+ */
+ return babl;
+ }
+
babl_assert (BABL_IS_BABL (source));
babl_assert (BABL_IS_BABL (destination));
return NULL;
}
- {
- Babl *ret = babl_db_insert (babl_fish_db (), babl);
- if (ret != babl)
- babl_free (babl);
- return ret;
- }
+ /* Since there is not an already registered instance by the required
+ * name, inserting newly created class into database.
+ */
+ babl_db_insert (babl_fish_db (), babl);
+ return babl;
}
static long
Babl *babl = NULL;
char *name = create_name (source, destination, 1);
+ babl = babl_db_exist_by_name (babl_fish_db (), name);
+ if (babl)
+ {
+ /* There is an instance already registered by the required name,
+ * returning the preexistent one instead.
+ */
+ return babl;
+ }
+
babl_assert (BABL_IS_BABL (source));
babl_assert (BABL_IS_BABL (destination));
babl->fish.error = 0.0; /* assuming the provided reference conversions for types
and models are as exact as possible
*/
- {
- Babl *ret = babl_db_insert (babl_fish_db (), babl);
- if (ret != babl)
- babl_free (babl);
- return ret;
- }
+
+ /* Since there is not an already registered instance by the required
+ * name, inserting newly created class into database.
+ */
+ babl_db_insert (babl_fish_db (), babl);
+ return babl;
}
name = create_name (conversion);
+ babl = babl_db_exist_by_name (babl_fish_db (), name);
+ if (babl)
+ {
+ /* There is an instance already registered by the required name,
+ * returning the preexistent one instead.
+ */
+ return babl;
+ }
+
babl = babl_malloc (sizeof (BablFishSimple) +
strlen (name) + 1);
babl->class_type = BABL_FISH_SIMPLE;
reference, and babl fish reference only requests clean
conversions */
- {
- Babl *ret = babl_db_insert (babl_fish_db (), babl);
- if (ret != babl)
- babl_free (babl);
- return ret;
- }
+ /* Since there is not an already registered instance by the required
+ * name, inserting newly created class into database.
+ */
+ babl_db_insert (babl_fish_db (), babl);
+ return babl;
}
{
Babl *babl;
- {
- int i;
- /* i is desintation position */
- for (i = 0; i < model->components; i++)
- {
- int j;
-
- for (j = 0; j < components; j++)
- {
- if (component[j] == model->component[i])
- goto component_found;
- }
- babl_fatal ("matching source component for %s in model %s not found",
- model->component[i]->instance.name, model->instance.name);
-component_found:
- ;
- }
- }
+ /* i is desintation position */
+ int i, j, component_found = 0;
+ for (i = 0; i < model->components; i++)
+ {
+ for (j = 0; j < components; j++)
+ {
+ if (component[j] == model->component[i])
+ {
+ component_found = 1;
+ break;
+ }
+ }
+ if (!component_found)
+ {
+ component_found = 0;
+ babl_fatal ("matching source component for %s in model %s not found",
+ model->component[i]->instance.name, model->instance.name);
+ }
+ }
/* allocate all memory in one chunk */
babl = babl_malloc (sizeof (BablFormat) +
va_end (varg);
- babl = format_new (name ? name : create_name (model, components, component, type),
+ if (!name)
+ name = create_name (model, components, component, type);
+
+ babl = babl_db_exist (db, id, name);
+ if (babl)
+ {
+ /* There is an instance already registered by the required id/name,
+ * returning the preexistent one instead.
+ */
+ return babl;
+ }
+
+ babl = format_new (name,
id,
planar, components, model,
component, sampling, type);
- {
- Babl *ret = babl_db_insert (db, babl);
- if (ret != babl)
- babl_free (babl);
- return ret;
- }
+ /* Since there is not an already registered instance by the required
+ * id/name, inserting newly created class into database.
+ */
+ babl_db_insert (db, babl);
+ return babl;
}
int
va_end (varg);
- babl = model_new (create_name (name, components, component), id, components, component);
+ name = create_name (name, components, component);
- {
- Babl *ret = babl_db_insert (db, babl);
- if (ret != babl)
- babl_free (babl);
- return ret;
- }
+ babl = babl_db_exist (db, id, name);
+ if (babl)
+ {
+ /* There is an instance already registered by the required id/name,
+ * returning the preexistent one instead.
+ */
+ return babl;
+ }
+
+ babl = model_new (name, id, components, component);
+
+ /* Since there is not an already registered instance by the required
+ * id/name, inserting newly created class into database.
+ */
+ babl_db_insert (db, babl);
+ return babl;
}
va_end (varg);
+ babl = babl_db_exist (db, id, first_arg);
+ if (babl)
+ {
+ /* There is an instance already registered by the required id/name,
+ * returning the preexistent one instead.
+ */
+ return babl;
+ }
+
babl = type_new (first_arg, id, bits);
- {
- Babl *ret = babl_db_insert (db, babl);
- if (ret != babl)
- babl_free (babl);
- return ret;
- }
+ /* Since there is not an already registered instance by the required
+ * id/name, inserting newly created class into database.
+ */
+ babl_db_insert (db, babl);
+ return babl;
}